#include "kran_komplett.h"

// Variablen fuer den Kran
double armBeweg = 27.5 + 20.0*0.5;
double hebelBeweg = 0.05 + 20.0*0.015;
double handHochRunter = 0.0;
double fingerAufZu = 2.0;

int container = 0;

GLfloat mat_rot[] = {1.0,0.0,0.0};
GLfloat mat_gruen[] = {0.0,1.0,0.0};
GLfloat mat_blau[] = {0.0,0.0,1.0};
GLfloat mat_weiss[] = {1.0,1.0,1.0};


// Hilfsfunktion, um den kompletten Kran zu zeichnen
void zeichneKomplettenKran() {
	glRotatef(180, 0.0,1.0,0.0);
	glTranslatef(2.0, 0.85, -5.0);
	glCallList(dlKran06Stopper);
	glRotatef(180, 0.0,1.0,0.0);
	/* --------------------------------------------- Schienen */
	glTranslatef(0.0, -0.85, 31.21);
	glCallList(dlKran01Schiene);

	/* --------------------------------------------- Stoppper */
	glTranslatef(0.0, 0.85, 31.21);
	glCallList(dlKran06Stopper);
	
	/* --------------------------------------------- Container */
	if(container == 0) {
		glTranslatef(8.8, -1.3, -40.0);
		glRotatef(-90,1,0,0);
		glRotatef(90,0,0,1);
		glScalef(0.5,0.5,0.5);
		draw_container(conAfrica,conAfrica_back);
		glScalef(2.0,2.0,2.0);
		glRotatef(-90,0,0,1);
		glRotatef(90,1,0,0);
		glTranslatef(-8.8, 1.3, 40.0);
	}
	else if(container == 3 || container == 4) {
		glTranslatef(-11.4, 1.21, -25.8);
		glRotatef(-90,1,0,0);
		glRotatef(90,0,0,1);
		glScalef(0.5,0.5,0.5);
			draw_container(conAfrica,conAfrica_back);
		glScalef(2.0,2.0,2.0);
		glRotatef(-90,0,0,1);
		glRotatef(90,1,0,0);
		glTranslatef(11.4, -1.21, 25.8);
	}
	/* ----------------------------------------------- Raeder */
	glTranslatef(-2.99, -0.13, 25.0+radBewegung);
	zeichneRadUndRadkappe();
	
	glTranslatef(0.0, 0.0, -7.5);
	zeichneRadUndRadkappe();

	glTranslatef(5.99, 0.0, 0.0);
	zeichneRadUndRadkappe();

	glTranslatef(0.0, 0.0, 7.5);
	zeichneRadUndRadkappe();
	
	/* ------------------------------------------ Mittelteil */
	glTranslatef(-2.99, 4.7, -3.25);
	glCallList(dlKran04Mittelteil);
	
	/* -------------------------------------------- Oberteil */
	glPushMatrix();
		glRotatef(oberteilRotate, 0.0, 1.0, 0.0);
		glTranslatef(0.0, 9.9, 2.4);
		glCallList(dlKran05Oberteil);
			/* ---------------------------- Der Scheinwerfer */
		glTranslatef(0.0, -4.6, 3.75);
		glScalef(0.1,0.1,0.1);
		glRotatef(12, 1.0,0.0,0.0);
		zeichneScheinwerfer();
		glRotatef(-12, 1.0,0.0,0.0);
		glScalef(10.0,10.0,10.0);
		glTranslatef(0.0, 4.6, -3.75);
	
		GLfloat lightKran_spot_direction[] = {0.0,-1.0, 1.0,};
		GLfloat lightKran_position[] = {0.0,-4.7,3.7, 1.0};
	
		glLightfv(GL_LIGHT7, GL_POSITION, lightKran_position);
		glLightfv(GL_LIGHT7, GL_SPOT_DIRECTION, lightKran_spot_direction);
		glLightf(GL_LIGHT7, GL_SPOT_EXPONENT, 10.0);
		glLightf(GL_LIGHT7, GL_SPOT_CUTOFF, 28.0);
		glLightfv(GL_LIGHT7, GL_AMBIENT, mat_gelblich);
		glLightfv(GL_LIGHT7, GL_DIFFUSE, mat_gelblich);
		glLightfv(GL_LIGHT7, GL_SPECULAR, mat_gelblich);
		glLightf(GL_LIGHT7, GL_CONSTANT_ATTENUATION, 1.2);

			/* ----------------------------------------- Arm */
		glPushMatrix();
			glTranslatef(0.0, 5.3, 4.3);
			glRotatef(armBeweg, 1.0, 0.0, 0.0);
			glCallList(dlKran05Arm);
		glPopMatrix();
			/* --------------------------------------- Hebel */
		glPushMatrix();
			glTranslatef(0.0, 0.0, 0.0);
			glTranslatef(0.0, hebelBeweg, 0.875*hebelBeweg);
			glCallList(dlKran05Hebel);
				/* ---------------------------------------- Seil */
			glTranslatef(0.0, -2.85*hebelBeweg, -3.0*0.875*hebelBeweg);
			glTranslatef(0.0, 3.0, 7.7);
			glLineWidth(5.0);
			zeichneSeil(-1.0+handHochRunter, 0.05);
			glTranslatef(0.0, -3.0, -7.7);
				/* ----------------------------------------- Hand*/
			glTranslatef(0.0, 2.0+handHochRunter, 7.7);

					/* ----------------------------------- Container */
				if(container == 1 || container == 2) {
					glTranslatef(-5.0,-4.1,-1.25);
					glRotatef(-90,1,0,0);
					glScalef(0.5,0.5,0.5);
					draw_container(conAfrica,conAfrica_back);
					glRotatef(90,1,0,0);
					glScalef(2.0,2.0,2.0);
					glTranslatef(5.0,4.1,1.25);
				}

			glRotatef(90, 0.0, 1.0, 0.0);
			glScalef(1.13,1.0,1.0);
			glCallList(dlKran07Hand);
			glRotatef(-90, 0.0, 1.0, 0.0);
				/* -------------------------------------- Finger */
			glRotatef(90, 0.0, 1.0, 0.0);
			glScalef(0.87,1.0,1.0);
			glTranslatef(fingerAufZu, -0.8, 0.0);
			glCallList(dlKran07Finger);
			glTranslatef(-2*fingerAufZu, 0.0, 0.0);
			glRotatef(180, 0.0,1.0,0.0);
			glCallList(dlKran07Finger);
		glPopMatrix();
	
	glPopMatrix();
}

// Hilfsfunktion zum Zeichnen zweier Raeder in einer Radkappe
void zeichneRadUndRadkappe() {
	glPushMatrix();
	glTranslatef(0.0, 0.0, 0.0);
	glRotatef(radRotate, 1.0, 0.0, 0.0);
	glCallList(dlKran02Rad);
	glPopMatrix();
	
	glPushMatrix();
	glTranslatef(0.0, 0.0, 1.1);
	glRotatef(radRotate, 1.0, 0.0, 0.0);
	glCallList(dlKran02Rad);
	glPopMatrix();

	glPushMatrix();
	glTranslatef(0.0, 0.53, 0.55);
	glCallList(dlKran03Radkappe);
	glPopMatrix();
}
